home *** CD-ROM | disk | FTP | other *** search
/ Underground / Underground CD1.iso / virii / zrodla / d / doors.asm < prev    next >
Encoding:
Assembly Source File  |  1998-01-14  |  6.6 KB  |  152 lines

  1. title   DOORS.ASM - Switch Color/Mono Screens On Keyboard Request
  2.  
  3. ;
  4.  
  5. VECTORS         segment at 0h           ; 8088 / 80286 Interrupt Vector Area
  6.  
  7.         org     9h*4                    ; IBM PC Keyboard is Int 9H
  8.  
  9. KB_INT_VECTOR   label   dword           ; Double word label
  10.  
  11. ;
  12.  
  13. VECTORS         ends
  14.  
  15. ;
  16.  
  17. ROM_BIOS_DATA   segment at 40h          ; Low Memory "BIOS" Parameters
  18.  
  19. ;
  20.  
  21.         org     10h                     ; Location of EQUIP_FLAG
  22.  
  23. EQUIP_FLAG      dw      ?               ; Contains video settings
  24.  
  25.                                         ; in bits 4 and 5
  26.  
  27. ;
  28.  
  29.         org     17h                     ; Location of KB_FLAG
  30.  
  31. KB_FLAG         db      ?               ; Contains Alt (bit 3) &
  32.  
  33.                                         ; Right Shift (bit 0) States
  34.  
  35. ROM_BIOS_DATA   ends
  36.  
  37. ;
  38.  
  39. ; Initialization Routine
  40.  
  41. ;
  42.  
  43. CODE_SEG        segment
  44.  
  45.         assume  cs:CODE_SEG
  46.  
  47.         org     100h                    ; COM program format
  48.  
  49. BEGIN:  jmp     SWAP_VECTORS            ; Initialize vectors and attach to DOS
  50.  
  51. ;
  52.  
  53. ROM_KB_INT      dd      0               ; Double word to save address of
  54.  
  55.                                         ; ROM-BIOS keyboard interrupt
  56.  
  57. ; DOORS_INT intercepts the keyboard interrupt and switches
  58.  
  59. ;      screens if [Alt]-[Right Shift] combination is pressed
  60.  
  61. ;
  62.  
  63. DOORS_INT       proc    near
  64.  
  65.         assume  ds:nothing
  66.  
  67.         push    ds                      ; Push all affected registers
  68.  
  69.         push    es
  70.  
  71.         push    ax
  72.  
  73.         push    bx
  74.  
  75.         push    cx
  76.  
  77.         push    dx
  78.  
  79.         push    si
  80.  
  81.         push    di
  82.  
  83. ;
  84.  
  85.         pushf                           ; Push Flags for fake interrupt call
  86.  
  87.         call    ROM_KB_INT              ; to BIOS program to read keyboard
  88.  
  89. ;
  90.  
  91.         assume  ds:ROM_BIOS_DATA        ; Define data segment to read
  92.  
  93.         mov     ax,ROM_BIOS_DATA        ; keyboard flag & equipment flag
  94.  
  95.         mov     ds,ax
  96.  
  97.         mov     al,KB_FLAG              ; Get keyboard flag
  98.  
  99.         and     al,09h                  ; Isolate [Alt] + [Right Shift]
  100.  
  101.         cmp     al,09h                  ; Are they pressed?
  102.  
  103.         jne     RETURN                  ; No, quit
  104.  
  105. ;
  106.  
  107. ; [Alt] + [Right Shift] are pressed -- Continue processing
  108.  
  109. ; Check on video mode - quit if not monochrome, color 80x25 or BW 80x25
  110.  
  111. ;
  112.  
  113.         mov     ah,15                   ; Call Func 15 of Int 10h to
  114.  
  115.         int     10h                     ; get video state of the PC
  116.  
  117.         cmp     al,7                    ; Is screen monochrome?
  118.  
  119.         je      SCREEN_OKAY             ; Yes, go switch screens
  120.  
  121.         cmp     al,3                    ; Is screen color text?
  122.  
  123.         jbe     CHECK_40_OR_80          ; Yes, go check for 80 or 40 char
  124.  
  125.         jmp     RETURN                  ; Screen is in graphics mode, quit
  126.  
  127. CHECK_40_or_80:
  128.  
  129.         cmp     al,1                    ; Is screen 40-character?
  130.  
  131.         jbe     RETURN                  ; Yes, quit
  132.  
  133. ;
  134.  
  135. SCREEN_OKAY:
  136.  
  137. ;
  138.  
  139. ; Save the current cursor position
  140.  
  141. ;
  142.  
  143.         mov     ah,3                    ; Call Func 3 of Int 10H
  144.  
  145.         mov     bh,0                    ; to read cursor position
  146.  
  147.         int     10h                     ; (page zero for color screen)
  148.  
  149. ;
  150.  
  151. ; Screen switch routine - Establish calling argument (AL) for Int 10h
  152.  
  153. ;
  154.  
  155.         mov     bx,EQUIP_FLAG           ; Current equipment flag to BX
  156.  
  157.         mov     cx,bx                   ; Make a copy of it in CX
  158.  
  159.         and     cx,30h                  ; Extract screen information
  160.  
  161.         xor     bx,cx                   ; Erase current screen information in BX
  162.  
  163.         or      bx,20h                  ; Set BX to color 80x25
  164.  
  165.         mov     al,3                    ; Set AL for color 80x25 in Int 10h
  166.  
  167.         cmp     cx,30h                  ; Is current mono?
  168.  
  169.         je      SET_MODE                ; Yes, switch to color
  170.  
  171.         or      bx,30h                  ; No, set BX for monochrome
  172.  
  173.         mov     al,7                    ; Set AL for monochrome in Int 10h
  174.  
  175. SET_MODE:
  176.  
  177.         mov     EQUIP_FLAG,bx           ; Write BX to equipment flag
  178.  
  179.         xor     ah,ah                   ; Use Func 0 of Int 10h to
  180.  
  181.         int     10h                     ; change screen parameters
  182.  
  183. ;
  184.  
  185. ; Restore Cursor
  186.  
  187. ;
  188.  
  189.         mov     ah,2                    ; Use Func 2 of Int 10h to restore
  190.  
  191.         mov     bh,0                    ; cursor on new screen (position in DX)
  192.  
  193.         int     10h
  194.  
  195. ;
  196.  
  197. ; After screens are switched, set DS and ES registers to move screen data
  198.  
  199. ;
  200.  
  201.         mov     ax,0b000h               ; Load ES with Mono Segment
  202.  
  203.         mov     es,ax
  204.  
  205.         mov     ax,0b800h               ; Load DS with Color Segment
  206.  
  207.         mov     ds,ax
  208.  
  209.         cmp     cx,30h                  ; Did we switch from mono?
  210.  
  211.         jne     COPY_THE_SCREEN         ; Yes, move data from mono to color
  212.  
  213.         push    ds                      ; No, swap ES and DS to move data
  214.  
  215.         push    es                      ; from color to mono
  216.  
  217.         pop     ds
  218.  
  219.         pop     es
  220.  
  221. COPY_THE_SCREEN:
  222.  
  223.         xor     di,di                   ; Start at zero offsets
  224.  
  225.         xor     si,si
  226.  
  227.         mov     cx,2000                 ; 2000 chars + attrs per screen
  228.  
  229.         cld                             ; Make sure move is 'forward'
  230.  
  231. rep     movsw                           ; Move Words with string instruction
  232.  
  233. ;
  234.  
  235. RETURN:
  236.  
  237.         pop     di                      ; Restore saved registers
  238.  
  239.         pop     si
  240.  
  241.         pop     dx
  242.  
  243.         pop     cx
  244.  
  245.         pop     bx
  246.  
  247.         pop     ax
  248.  
  249.         pop     es
  250.  
  251.         pop     ds
  252.  
  253.         iret                            ; Return to system
  254.  
  255.  
  256.  
  257. DOORS_INT       endp
  258.  
  259. ;
  260.  
  261. ; This procedure initializes the new keyboard interupt vectors
  262.  
  263. ;
  264.  
  265. SWAP_VECTORS    proc    near
  266.  
  267.         assume  ds:VECTORS
  268.  
  269.         mov     ax,VECTORS                      ; Set up the data
  270.  
  271.         mov     ds,ax                           ; segment for vectors
  272.  
  273.         cli                                     ; Disable interrupts
  274.  
  275.         mov     ax,word ptr KB_INT_VECTOR       ; Store addresses
  276.  
  277.         mov     word ptr ROM_KB_INT,ax          ; of BIOS program
  278.  
  279.         mov     ax,word ptr KB_INT_VECTOR[2]
  280.  
  281.         mov     word ptr ROM_KB_INT[2],ax
  282.  
  283.         mov     word ptr KB_INT_VECTOR, offset DOORS_INT ; Substitute Our
  284.  
  285.         mov     word ptr KB_INT_VECTOR[2],cs             ; Program
  286.  
  287.         sti                                     ; Enable interrupts
  288.  
  289.         mov     dx,offset SWAP_VECTORS          ; End of new resident
  290.  
  291.                                                 ; program
  292.  
  293.         int     27h                             ; Terminate resident
  294.  
  295. SWAP_VECTORS    endp
  296.  
  297. CODE_SEG        ends
  298.  
  299.         end     BEGIN
  300.  
  301. ;
  302.  
  303.